package com.xinghou.platform.dao.main.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.ReportReasonsConfigDAO;
import com.xinghou.platform.model.main.ReportReasonsConfig;

/**
 * @author liuwei.wen
 *
 */
@Service
public class ReportReasonsConfigDAOImpl {/*

	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public ReportReasonsConfig getReportReasonsConfigByreasonId(Integer reasonId)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT 	Reason_Id,NAME,TYPE FROM  report_reasons_config where Reason_Id = ?";
		ReportReasonsConfig reportReasonsConfig = jdbcTemplate.queryForObject(sql, new Object[] {reasonId}, new ReportReasonsConfigMapper());
		CustomerContextHolder.clearCustomerType();
		return reportReasonsConfig;
	}

	@Override
	public int updateReportReasonsConfig(ReportReasonsConfig reportReasonsConfig)throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("UPDATE report_reasons_config  SET NAME = ?,TYPE = ? WHERE Reason_Id = ? ;");					
		Object[] params = {reportReasonsConfig.getName(),reportReasonsConfig.getType(),reportReasonsConfig.getReasonId()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveReportReasonsConfig(ReportReasonsConfig reportReasonsConfig)throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("INSERT INTO report_reasons_config (NAME,TYPE) VALUES(?,?);");			
		Object[] params = {reportReasonsConfig.getName(),reportReasonsConfig.getType()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret =jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	
	@Override
	public List<ReportReasonsConfig> getReportReasonsConfiglistBytype(Short type)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Reason_Id,NAME,TYPE FROM  report_reasons_config where TYPE=?";
		List<ReportReasonsConfig> reportReasonsConfiglist=(List<ReportReasonsConfig>)jdbcTemplate.query(sql,new Object[] {type},new ReportReasonsConfigMapper());
	    CustomerContextHolder.clearCustomerType();
		return reportReasonsConfiglist;
	}
	private static final class ReportReasonsConfigMapper implements RowMapper<ReportReasonsConfig> {
		public ReportReasonsConfig mapRow(ResultSet rs, int rowNum) throws SQLException {
			ReportReasonsConfig reportReasonsConfig = new ReportReasonsConfig();
			reportReasonsConfig.setName(rs.getString("NAME"));
			reportReasonsConfig.setReasonId(rs.getInt("Reason_Id"));
			reportReasonsConfig.setType(rs.getShort("TYPE"));
			return reportReasonsConfig;
		}
	}*/
}
